package GameBoard;

import java.util.Vector;
import GameElements.Pawn;
import GameElements.Tile;
import Player.Player;

public class BasicGameBoard extends GameBoard 
{
	public BasicGameBoard()
	{
		initTable();
		initStock();
		melangerStock();
	}
	
	protected void initTable()
	{
		int[] tile_d_Link = {1,1,1,  2,3,4,  4,4,4,  4,3,2};
		String path = "img/tiles/";
		table[width/2][height/2] = new Tile(path + "tile-d.png", Tile.castle, Tile.street, Tile.farm, Tile.street, tile_d_Link);	
	}
		
	protected void initStock()
	{	
		int[] tile_a_Link = {1,1,1,  1,1,1,  1,2,1,  1,1,1};
		int[] tile_b_Link = {1,1,1,  1,1,1,  1,1,1,  1,1,1};
		int[] tile_c_Link = {1,1,1,  1,1,1,  1,1,1,  1,1,1};		
		int[] tile_d_Link = {1,1,1,  2,3,4,  4,4,4,  4,3,2};		
		int[] tile_e_Link = {1,1,1,  1,1,1,  1,1,1,  2,2,2};		
		int[] tile_f_Link = {1,1,1,  2,2,2,  3,3,3,  2,2,2};		
		int[] tile_g_Link = {1,1,1,  2,2,2,  3,3,3,  2,2,2};		
		int[] tile_h_Link = {1,1,1,  2,2,2,  1,1,1,  3,3,3};
		int[] tile_i_Link = {1,1,1,  2,2,2,  3,3,3,  3,3,3};		
		int[] tile_j_Link = {1,1,1,  2,3,4,  4,3,2,  2,2,2};		
		int[] tile_k_Link = {1,1,1,  2,2,2,  2,3,4,  4,3,2};		
		int[] tile_l_Link = {1,1,1,  2,3,4,  4,5,6,  6,7,2};//*********
		int[] tile_m_Link = {1,1,1,  2,2,2,  2,2,2,  1,1,1};		
		int[] tile_n_Link = {1,1,1,  2,2,2,  2,2,2,  1,1,1};		
		int[] tile_o_Link = {1,1,1,  2,3,4,  4,3,2,  1,1,1};
		int[] tile_p_Link = {1,1,1,  2,3,4,  4,3,2,  1,1,1};		
		int[] tile_q_Link = {1,1,1,  1,1,1,  2,2,2,  1,1,1};
		int[] tile_r_Link = {1,1,1,  1,1,1,  2,2,2,  1,1,1};
		int[] tile_s_Link = {1,1,1,  1,1,1,  2,3,4,  1,1,1};
		int[] tile_t_Link = {1,1,1,  1,1,1,  2,3,4,  1,1,1};		
		int[] tile_u_Link = {1,2,3,  3,3,3,  3,2,1,  1,1,1};		
		int[] tile_v_Link = {1,1,1,  1,1,1,  1,2,3,  3,2,1};		
		int[] tile_w_Link = {1,1,1,  2,3,4,  4,5,6,  6,7,2};//********
		int[] tile_x_Link = {1,2,3,  3,4,5,  5,6,7,  7,8,1};//********
	
		String path = "img/tiles/";
		stock.add(new Tile(path + "tile-a.png", Tile.farm, Tile.farm, Tile.street, Tile.farm, Tile.cloister, tile_a_Link));
		stock.add(new Tile(path + "tile-a.png", Tile.farm, Tile.farm, Tile.street, Tile.farm, Tile.cloister, tile_a_Link));
		
		stock.add(new Tile(path + "tile-b.png", Tile.farm, Tile.farm, Tile.farm, Tile.farm, Tile.cloister, tile_b_Link));
		stock.add(new Tile(path + "tile-b.png", Tile.farm, Tile.farm, Tile.farm, Tile.farm, Tile.cloister, tile_b_Link));
		stock.add(new Tile(path + "tile-b.png", Tile.farm, Tile.farm, Tile.farm, Tile.farm, Tile.cloister, tile_b_Link));
		stock.add(new Tile(path + "tile-b.png", Tile.farm, Tile.farm, Tile.farm, Tile.farm, Tile.cloister, tile_b_Link));
		
		stock.add(new Tile(path + "tile-c.png", Tile.castle, Tile.castle, Tile.castle, Tile.castle, tile_c_Link));
		
		stock.add(new Tile(path + "tile-d.png", Tile.castle, Tile.street, Tile.farm, Tile.street, tile_d_Link));
		stock.add(new Tile(path + "tile-d.png", Tile.castle, Tile.street, Tile.farm, Tile.street, tile_d_Link));
		stock.add(new Tile(path + "tile-d.png", Tile.castle, Tile.street, Tile.farm, Tile.street, tile_d_Link));
		
		stock.add(new Tile(path + "tile-e.png", Tile.castle, Tile.farm, Tile.farm, Tile.farm, tile_e_Link));
		stock.add(new Tile(path + "tile-e.png", Tile.castle, Tile.farm, Tile.farm, Tile.farm, tile_e_Link));
		stock.add(new Tile(path + "tile-e.png", Tile.castle, Tile.farm, Tile.farm, Tile.farm, tile_e_Link));
		stock.add(new Tile(path + "tile-e.png", Tile.castle, Tile.farm, Tile.farm, Tile.farm, tile_e_Link));
		stock.add(new Tile(path + "tile-e.png", Tile.castle, Tile.farm, Tile.farm, Tile.farm, tile_e_Link));

		stock.add(new Tile(path + "tile-f.png", Tile.farm, Tile.castle, Tile.farm, Tile.castle, tile_f_Link));
		stock.add(new Tile(path + "tile-f.png", Tile.farm, Tile.castle, Tile.farm, Tile.castle, tile_f_Link));
		
		stock.add(new Tile(path + "tile-g.png", Tile.farm, Tile.castle, Tile.farm, Tile.castle, tile_g_Link));
		
		stock.add(new Tile(path + "tile-h.png", Tile.farm, Tile.castle, Tile.farm, Tile.castle, tile_h_Link));
		stock.add(new Tile(path + "tile-h.png", Tile.farm, Tile.castle, Tile.farm, Tile.castle, tile_h_Link));
		stock.add(new Tile(path + "tile-h.png", Tile.farm, Tile.castle, Tile.farm, Tile.castle, tile_h_Link));
		
		stock.add(new Tile(path + "tile-i.png", Tile.castle, Tile.castle, Tile.farm, Tile.farm, tile_i_Link));
		stock.add(new Tile(path + "tile-i.png", Tile.castle, Tile.castle, Tile.farm, Tile.farm, tile_i_Link));

		stock.add(new Tile(path + "tile-j.png", Tile.castle, Tile.street, Tile.street, Tile.farm, tile_j_Link));
		stock.add(new Tile(path + "tile-j.png", Tile.castle, Tile.street, Tile.street, Tile.farm, tile_j_Link));
		stock.add(new Tile(path + "tile-j.png", Tile.castle, Tile.street, Tile.street, Tile.farm, tile_j_Link));

		stock.add(new Tile(path + "tile-k.png", Tile.castle, Tile.farm, Tile.street, Tile.street, tile_k_Link));
		stock.add(new Tile(path + "tile-k.png", Tile.castle, Tile.farm, Tile.street, Tile.street, tile_k_Link));
		stock.add(new Tile(path + "tile-k.png", Tile.castle, Tile.farm, Tile.street, Tile.street, tile_k_Link));

		stock.add(new Tile(path + "tile-l.png", Tile.castle, Tile.street, Tile.street, Tile.street, tile_l_Link));
		stock.add(new Tile(path + "tile-l.png", Tile.castle, Tile.street, Tile.street, Tile.street, tile_l_Link));
		stock.add(new Tile(path + "tile-l.png", Tile.castle, Tile.street, Tile.street, Tile.street, tile_l_Link));

		stock.add(new Tile(path + "tile-m.png", Tile.castle, Tile.farm, Tile.farm, Tile.castle, tile_m_Link));
		stock.add(new Tile(path + "tile-m.png", Tile.castle, Tile.farm, Tile.farm, Tile.castle, tile_m_Link));

		stock.add(new Tile(path + "tile-n.png", Tile.castle, Tile.farm, Tile.farm, Tile.castle, tile_n_Link));
		stock.add(new Tile(path + "tile-n.png", Tile.castle, Tile.farm, Tile.farm, Tile.castle, tile_n_Link));
		stock.add(new Tile(path + "tile-n.png", Tile.castle, Tile.farm, Tile.farm, Tile.castle, tile_n_Link));

		stock.add(new Tile(path + "tile-o.png", Tile.castle, Tile.street, Tile.street, Tile.castle, tile_o_Link));
		stock.add(new Tile(path + "tile-o.png", Tile.castle, Tile.street, Tile.street, Tile.castle, tile_o_Link));

		stock.add(new Tile(path + "tile-p.png", Tile.castle, Tile.street, Tile.street, Tile.castle, tile_p_Link));
		stock.add(new Tile(path + "tile-p.png", Tile.castle, Tile.street, Tile.street, Tile.castle, tile_p_Link));
		stock.add(new Tile(path + "tile-p.png", Tile.castle, Tile.street, Tile.street, Tile.castle, tile_p_Link));

		stock.add(new Tile(path + "tile-q.png", Tile.castle, Tile.castle, Tile.farm, Tile.castle, tile_q_Link));
		
		stock.add(new Tile(path + "tile-r.png", Tile.castle, Tile.castle, Tile.farm, Tile.castle, tile_r_Link));
		stock.add(new Tile(path + "tile-r.png", Tile.castle, Tile.castle, Tile.farm, Tile.castle, tile_r_Link));
		stock.add(new Tile(path + "tile-r.png", Tile.castle, Tile.castle, Tile.farm, Tile.castle, tile_r_Link));

		stock.add(new Tile(path + "tile-s.png", Tile.castle, Tile.castle, Tile.street, Tile.castle, tile_s_Link));
		stock.add(new Tile(path + "tile-s.png", Tile.castle, Tile.castle, Tile.street, Tile.castle, tile_s_Link));

		stock.add(new Tile(path + "tile-t.png", Tile.castle, Tile.castle, Tile.street, Tile.castle, tile_t_Link));

		stock.add(new Tile(path + "tile-u.png", Tile.street, Tile.farm, Tile.street, Tile.farm, tile_u_Link));
		stock.add(new Tile(path + "tile-u.png", Tile.street, Tile.farm, Tile.street, Tile.farm, tile_u_Link));
		stock.add(new Tile(path + "tile-u.png", Tile.street, Tile.farm, Tile.street, Tile.farm, tile_u_Link));
		stock.add(new Tile(path + "tile-u.png", Tile.street, Tile.farm, Tile.street, Tile.farm, tile_u_Link));
		stock.add(new Tile(path + "tile-u.png", Tile.street, Tile.farm, Tile.street, Tile.farm, tile_u_Link));
		stock.add(new Tile(path + "tile-u.png", Tile.street, Tile.farm, Tile.street, Tile.farm, tile_u_Link));
		stock.add(new Tile(path + "tile-u.png", Tile.street, Tile.farm, Tile.street, Tile.farm, tile_u_Link));
		stock.add(new Tile(path + "tile-u.png", Tile.street, Tile.farm, Tile.street, Tile.farm, tile_u_Link));

		stock.add(new Tile(path + "tile-v.png", Tile.farm, Tile.farm, Tile.street, Tile.street, tile_v_Link));
		stock.add(new Tile(path + "tile-v.png", Tile.farm, Tile.farm, Tile.street, Tile.street, tile_v_Link));
		stock.add(new Tile(path + "tile-v.png", Tile.farm, Tile.farm, Tile.street, Tile.street, tile_v_Link));
		stock.add(new Tile(path + "tile-v.png", Tile.farm, Tile.farm, Tile.street, Tile.street, tile_v_Link));
		stock.add(new Tile(path + "tile-v.png", Tile.farm, Tile.farm, Tile.street, Tile.street, tile_v_Link));
		stock.add(new Tile(path + "tile-v.png", Tile.farm, Tile.farm, Tile.street, Tile.street, tile_v_Link));
		stock.add(new Tile(path + "tile-v.png", Tile.farm, Tile.farm, Tile.street, Tile.street, tile_v_Link));
		stock.add(new Tile(path + "tile-v.png", Tile.farm, Tile.farm, Tile.street, Tile.street, tile_v_Link));
		stock.add(new Tile(path + "tile-v.png", Tile.farm, Tile.farm, Tile.street, Tile.street, tile_v_Link));

		stock.add(new Tile(path + "tile-w.png", Tile.farm, Tile.street, Tile.street, Tile.street, tile_w_Link));
		stock.add(new Tile(path + "tile-w.png", Tile.farm, Tile.street, Tile.street, Tile.street, tile_w_Link));
		stock.add(new Tile(path + "tile-w.png", Tile.farm, Tile.street, Tile.street, Tile.street, tile_w_Link));
		stock.add(new Tile(path + "tile-w.png", Tile.farm, Tile.street, Tile.street, Tile.street, tile_w_Link));

		stock.add(new Tile(path + "tile-x.png", Tile.street, Tile.street, Tile.street, Tile.street, tile_x_Link));
	}

	public void distributePawn(Vector<Player> player)
	{
		String[] pawnImgName = {"green_pawn.png", "red_pawn.png", "blue_pawn.png", "yellow_pawn.png", "black_pawn.png"};
		String path = "img/pawns/";
		for(int i=0; i<player.size(); i++)
		{
			Vector<Pawn> pawn = new Vector<Pawn>();
			for(int j=0; j<8; j++)
				pawn.add(new Pawn(path + pawnImgName[i]));
			
			player.get(i).setPawn(pawn);
		}
	}

	
	public boolean canAdd(Tile t, int i, int j)
	{
		if(i >= width - 1 || j >= height - 1 || i <= 1 || j <= 1 )
			return false;
		
		//la place n'est pas occupé
		if(table[i][j] != null)
			return false;

		Tile tN = table[i][j-1];
		Tile tE = table[i+1][j];
		Tile tS = table[i][j+1]; 
		Tile tW = table[i-1][j];
		
		//au moin un voisin
		if(!(tN!=null || tE!=null || tS!=null || tW!=null))
			return false;
		
		//test nord
		if(tN != null)
			if(t.getNorth() != tN.getSouth())
				return false;
		//test est
		if(tE != null)
			if(t.getEast() != tE.getWest())
				return false;
		//test sud
		if(tS != null)
			if(t.getSouth() != tS.getNorth())
				return false;
		//test ouest
		if(tW != null)
			if(t.getWest() != tW.getEast())
				return false;
			
		return true;
	}
	public void add(Tile t, int i, int j)
	{
		table[i][j] = t;
	}
	
	
	public boolean canAdd(Pawn pawn, int i, int j, int indexPawnInTile)
	{
		//add the pawn to the cloister(in the center of the tile)
		if(indexPawnInTile == Tile.c)
			return true;
		
		return false;//**************************tmp
	}
	public void add(Pawn pawn, int i, int j, int indexPawnInTile)
	{
		table[i][j].setPawn(pawn, indexPawnInTile);
		//System.out.println(i + " " + j + " " + " " + indexPawnInTile);
	}
}
